<?php
class Detail extends MY_Controller
{
	public function __construct()
	{
		log_message('debug', '=====开始调用Pay->Detail->__construct接口=====');
		parent::__construct();
		$this->loadLanguageFile('application/controllers/Pay/');
		log_message('debug', '=====调用Pay->Detail->__construct接口结束=====');
	}
	
	public function showView() {
		$this->load->view('module/Pay/detail.htm');
	}
	
	public function getListData() {
		log_message('debug', '=====开始调用Pay->Detail->getListData接口=====');
		$this->verifyPrivilege();
		
		try{
			$gameAreaId = $this->param->getParam('gameAreaId', array('method' => 'int', 'min' => 1, 'emptyErrorCode' => 201, 'invalidErrorCode' => 1));
			$account = $this->param->getParam('account', array('method' => 'string', 'emptyErrorCode' => 1, 'invalidErrorCode' => 1), 'post', true);
			$roleName = $this->param->getParam('roleName', array('method' => 'string', 'emptyErrorCode' => 1, 'invalidErrorCode' => 1), 'post', true);
			$startDateTime = $this->param->getParam('startDateTime', array('method' => 'string', 'emptyErrorCode' => 1, 'invalidErrorCode' => 1), 'post', true);
			$endDateTime = $this->param->getParam('endDateTime', array('method' => 'string', 'emptyErrorCode' => 1, 'invalidErrorCode' => 1), 'post', true);
			$page = $this->param->getParam('page', array('method' => 'int', 'min' => 1, 'emptyErrorCode' => 1, 'invalidErrorCode' => 1), 'post', true);
			$rows = $this->param->getParam('rows', array('method' => 'int', 'min' => 1, 'emptyErrorCode' => 1, 'invalidErrorCode' => 1), 'post', true);
			$this->initGameAreaInfo($gameAreaId);
			
			$this->initGmDatabase();
			$sql = "select `userId` from t_data_game_account where account = '$account'";
			$userId = $this->gmDatabase->getColumn($sql);
			//error_log("userID = ".$userId);
			
			$sql = "
				select
					<selectColumns>
				from
					`t_data_game_pay` a
				left join
					`t_data_game_account` b
				on
					b.`userId` = a.`userId`
				where
					b.`gameAreaId` = '{$gameAreaId}'
			";
			if($account || $roleName){
				$sql .= "
				 		and
				 		(
						`account` = '{$account}'
						or
						`roleName` = '{$roleName}'
					)
				 ";
			}
			if($startDateTime) {
				$sql .= " and `payDateTime` >= '{$startDateTime}'";
			}
			
			if($endDateTime) {
				$sql .= " and `payDateTime` <= '{$endDateTime}'";
			}
			
			$getTotalSql = str_replace('<selectColumns>', "count(*)", $sql);
			//error_log("getTotal sql = ".$getTotalSql);
			$this->returnData['data']['total'] = $this->gmDatabase->getColumn($getTotalSql);
			
			$getDataSql = str_replace('<selectColumns>', "`orderId`, b.`account` as userId, b.`roleName` as roleName, `money`, `gold`, `payDateTime`", $sql);
			if($page && $rows) {
				$startRow = ($page - 1) * $rows;
				$getDataSql .= " limit {$startRow}, {$rows}";
			}
			//error_log("getDataSql sql = ".$getDataSql);
			$res = $this->gmDatabase->getArray($getDataSql);
			$this->returnData['data']['rows'] = $res;
		}
		
		catch(MY_Param_Exception $e) {
			$this->setErrorCode($e->getCode());
		}
		
		catch(MY_Mysql_Exception $e) {
			$this->setErrorCode(1);
		}
		
		catch(Exception $e) {
			$this->setErrorCode($e->getCode());
		}
		
		$this->returnJson();
		
		log_message('debug', '=====调用Pay->Detail->getListData接口结束=====');
	}
}